package Server.Agent;

import java.io.FileInputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.lang.StringUtils;

public class GameConfig{	
	static final boolean SSL = System.getProperty("ssl") != null;
	static final int PORT = Integer.parseInt(System.getProperty("port", SSL ? "8443" : "9300"));
	
	Properties m_pp = new Properties();  
	
	private static class SingletonHolder {
		private static final GameConfig INSTANCE = new GameConfig();
	}
	public static final GameConfig getInstance() {
		return SingletonHolder.INSTANCE;
	}		
	public GameConfig() {
		try
		{
	        String configpath = "./server.ini";  
		    
		    FileInputStream fis = new FileInputStream(configpath);  
		    m_pp.load(fis);    
	    		    
		    get("TCP_PORT");
		    get("APP_HOST");
		    
		    get("IP");
		    get("PORT");
		    get("USER");
		    get("PASS");
		    get("NAME");
		}catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	public String get(String key){		
	    try
	    {
	    	if(m_pp.get(key) != null)
	    	{
		    	String value = m_pp.get(key).toString();
		    	System.out.println( key + " : " + value);
			    return value;	
	    	}else{
	    		System.out.println( key + " : unknown");
	    	}
		}catch(Exception e)
		{
			e.printStackTrace();
		}

		return null;
	}
	public int optInt(String key){		
	    try
	    {
	    	if(m_pp.get(key) != null)
	    	{
		    	String value = m_pp.get(key).toString();
		    	System.out.println( key + " : " + value);
		    	
			    return Integer.parseInt(value);	
	    	}else{
	    		System.out.println( key + " : unknown");
	    	}
		}catch(Exception e)
		{
			e.printStackTrace();
		}

		return 0;
	}
}